package com.angcyo.selenium.auto.action

import com.angcyo.javafx.base.ex.onBack
import com.angcyo.library.file.fileName
import com.angcyo.selenium.PairOutputType
import com.angcyo.selenium.auto.BaseControl
import com.angcyo.selenium.bean.putMap
import com.angcyo.selenium.auto.parse.HandleResult

/**
 * Email:angcyo@126.com
 * @author angcyo
 * @date 2021/01/15
 */
abstract class BaseCodeAction : BaseAction() {

    fun saveCodeValue(
        control: BaseControl,
        result: HandleResult,
        key: String,
        codeValue: String?,
        codeImageData: String
    ) {
        if (!codeValue.isNullOrEmpty()) {
            result.success = true

            //保存起来
            control._currentTaskBean?.putMap(key, codeValue)

            //保存验证码图片
            onBack {
                PairOutputType().apply {
                    fileName = fileName(suffix = "_${key}_${codeValue}.png")
                    convertFromBase64Png(codeImageData)
                }
            }
        }
    }
}